package demo2;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description：
 * User：user
 * DATE:2021-10-29
 * Time:18:21
 */

interface  TT1{
    void funTT1();
}

interface  TT2 extends  TT1{
    void funTT2();
}
//扩展
interface  TT3 extends  TT2{
    void funTT3();
}
class TTClass implements  TT3{

    @Override
    public void funTT1() {

    }

    @Override
    public void funTT2() {

    }

    @Override
    public void funTT3() {

    }
}
class Student implements Comparable<Student>{
    public  String name;
    public double score;
    public int age;

    public Student(String name, double score, int age) {
        this.name = name;
        this.score = score;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        /*if(this.age > o.age ){
            return  1;
        }else if (this.age == o.age){
            return 0;
        }else{
            return -1;
        }*/
        //return this.age - o.age;//从小到大排列
        //return o.age - this.age;//从大到小排列
        return this.name.compareTo(o.name);//字符串排序
        //return this.name.comparTo(o.name);
        // string 实现了Compareable接口可以调用compareTo方法

    }
}
class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}

class NameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
class ScoreComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        //注意此处是将double转化为int
        return (int)(o1.score - o2.score);
    }
}
public class Test4 {

    public static void main(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("z张三",20.5,25);
        students[1] = new Student("b李四",22.5,15);
        students[2] = new Student("c王五",25.5,35);
        AgeComparator ageComparator = new AgeComparator();
        NameComparator nameComparator = new NameComparator();
        ScoreComparator scoreComparator = new ScoreComparator();
        Arrays.sort(students,scoreComparator);
        System.out.println(Arrays.toString(students));

    }
    public static void main4(String[] args) {
       Student student1 =  new Student("a张三",20.5,25);
        Student student2 =  new Student("b李四",22.5,15);
        System.out.println(student1.compareTo(student2));
    }
    public static void main3(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("z张三",20.5,25);
        students[1] = new Student("b李四",22.5,15);
        students[2] = new Student("c王五",25.5,35);
        Arrays.sort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void main1(String[] args) {
        int[] arry = new int[]{1,2,3};
        Arrays.sort(arry);
        System.out.println(Arrays.toString(arry));
    }
}
